﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;

namespace Streambolics.Gui
{

    /// <summary>
    ///     Base class for all Controls
    /// </summary>
    /// <remarks><para>
    ///     All standard controls provide support for the following
    ///     features:
    ///     <list type="bullet"><item>
    ///         Drag-and-drop, including customized cursors.
    ///     </item><item>
    ///         Text rendering
    ///     </item></list>
    /// </para></remarks>

    public partial class StandardControl : Control
    {
        private IDisposable components;

        /// <summary>
        ///     Renders the control text in the given rectangle.
        /// </summary>
        /// <param name="aGraphics">
        ///     The <c>Graphics</c> canvas on which to paint the text.
        /// </param>
        /// <param name="aRect">
        ///     The rectangle within <c>aGraphics</c> where to paint the
        ///     text.
        /// </param>
        /// <remarks><para>
        ///     This method retrieves the appropriate data from the predefined
        ///     properties of all controls: <c>Text</c>, <c>Font</c>, <c>ForeColor</c>
        /// </para></remarks>

        protected void RenderText (Graphics aGraphics, Rectangle aRect)
        {
            Brush b = new SolidBrush (ForeColor);
            StringFormat f = new StringFormat ();
            f.Alignment = StringAlignment.Center;
            f.LineAlignment = StringAlignment.Center;
            RectangleF r = new RectangleF (aRect.X, aRect.Y, aRect.Width, aRect.Height);
            aGraphics.DrawString (Text, Font, b, r, f);
        }

        protected override void OnMouseDown (MouseEventArgs e)
        {
            base.OnMouseDown (e);
            drag_MouseDown (e);
        }

        protected override void OnMouseUp (MouseEventArgs e)
        {
            base.OnMouseUp (e);
            drag_MouseUp (e);
        }

        protected override void OnMouseLeave (EventArgs e)
        {
            base.OnMouseLeave (e);
            drag_MouseLeave (e);
        }

        protected override void OnMouseMove (MouseEventArgs e)
        {
            base.OnMouseMove (e);
            drag_MouseMove (e);
        }

        partial void OnThisBeginLoading (EventArgs e)
        {
            StandardForm.MainBeginUpdate ();
        }

        partial void OnThisEndLoading (EventArgs e)
        {
            StandardForm.MainEndUpdate ();
        }

    }
}
